impl Solution {
    pub fn watering_plants(plants: Vec<i32>,mut capacity: i32) -> i32 {
        let t=capacity;
        let mut dif=Vec::from([0].repeat(plants.len()));
        dif[plants.len()-1]=1;
        for (ind,&v) in plants.iter().enumerate(){
            capacity-=v;
            if capacity>=0{
                continue;
            }else{
                capacity=t-v;
                dif[ind-1]+=2;
            }
        };
        let mut ans=1;
        for i in (0..dif.len()-1).rev(){
            dif[i]+=dif[i+1];
            ans+=dif[i];
        };
        return  ans;
        
    }
}
// 1 1

// 3 3 1
// 3 3 1 1
// 5 5 3 3 1
//      5 5 3 1 1